//全局
`define RstEnable 1'b1
`define RstDisable 1'b0

`define ChipEnable 1'b1
`define ChipDisable 1'b0

`define WriteEnable 1'b1
`define WriteDisable 1'b0
`define ReadEnable 1'b1
`define ReadDisable 1'b0
`define ZeroWord 32'h00000000

`define AluOpWidth 8
// `define AluSelWidth 3
`define InstValid 1'b0
`define InstInvalid 1'b1


// 指令
//逻辑运算指令
`define INST_AND  6'b100100
`define INST_OR   6'b100101
`define INST_XOR 6'b100110
`define INST_NOR 6'b100111
`define INST_ANDI 6'b001100
`define INST_ORI  6'b001101
`define INST_XORI 6'b001110
`define INST_LUI 6'b001111
//********************************
//移位指令
`define INST_SLL  6'b000000
`define INST_SLLV  6'b000100
`define INST_SRL  6'b000010
`define INST_SRLV  6'b000110
`define INST_SRA  6'b000011
`define INST_SRAV  6'b000111
`define INST_SYNC  6'b001111
`define INST_PREF  6'b110011
//*********************************
//移动指令
`define INST_MOVZ  6'b001010
`define INST_MOVN  6'b001011
`define INST_MFHI  6'b010000
`define INST_MTHI  6'b010001
`define INST_MFLO  6'b010010
`define INST_MTLO  6'b010011
//*********************************
//简单算术指令
`define INST_SLT  6'b101010
`define INST_SLTU  6'b101011
`define INST_SLTI  6'b001010
`define INST_SLTIU  6'b001011   
`define INST_ADD  6'b100000
`define INST_ADDU  6'b100001
`define INST_SUB  6'b100010
`define INST_SUBU  6'b100011
`define INST_ADDI  6'b001000
`define INST_ADDIU  6'b001001
`define INST_CLZ  6'b100000
`define INST_CLO  6'b100001

`define INST_MULT  6'b011000
`define INST_MULTU  6'b011001
`define INST_MUL  6'b000010
//***************************************

//乘累加，乘累减指令
`define INST_MADD  6'b000000
`define INST_MADDU  6'b000001
`define INST_MSUB  6'b000100
`define INST_MSUBU  6'b000101
//************************************
//除法指令
`define INST_DIV  6'b011010
`define INST_DIVU  6'b011011
//**********************
//分支转移指令
`define INST_J  6'b000010
`define INST_JAL  6'b000011
`define INST_JALR  6'b001001
`define INST_JR  6'b001000
`define INST_BEQ  6'b000100
`define INST_BGEZ  5'b00001
`define INST_BGEZAL  5'b10001
`define INST_BGTZ  6'b000111
`define INST_BLEZ  6'b000110
`define INST_BLTZ  5'b00000
`define INST_BLTZAL  5'b10000
`define INST_BNE  6'b000101
//**********************************
//访存类指令
`define INST_LB  6'b100000
`define INST_LBU  6'b100100
`define INST_LH  6'b100001
`define INST_LHU  6'b100101
`define INST_LL  6'b110000
`define INST_LW  6'b100011
`define INST_LWL  6'b100010
`define INST_LWR  6'b100110
`define INST_SB  6'b101000
`define INST_SC  6'b111000
`define INST_SH  6'b101001
`define INST_SW  6'b101011
`define INST_SWL  6'b101010
`define INST_SWR  6'b101110
//*****************************
//协处理器访问指令
`define INST_COP0 6'b010000
`define MTC0 5'b00100
`define MFC0 5'b00000
//*********************************
// `define INST_NOP 6'b000000

 
// AluOp
`define ALU_AND_OP   8'b00100100
`define ALU_OR_OP    8'b00100101
`define ALU_XOR_OP  8'b00100110
`define ALU_NOR_OP  8'b00100111
`define ALU_LUI_OP  8'b01011100   

`define ALU_SLL_OP  8'b01111100
`define ALU_SRL_OP  8'b00000010
`define ALU_SRA_OP  8'b00000011

`define ALU_MOVZ_OP  8'b00001010
`define ALU_MOVN_OP  8'b00001011
`define ALU_MFHI_OP  8'b00010000
`define ALU_MTHI_OP  8'b00010001
`define ALU_MFLO_OP  8'b00010010
`define ALU_MTLO_OP  8'b00010011


`define ALU_SLT_OP  8'b00101010
`define ALU_SLTU_OP  8'b00101011

`define ALU_ADD_OP  8'b00100000
`define ALU_ADDU_OP  8'b00100001
`define ALU_SUB_OP  8'b00100010
`define ALU_SUBU_OP  8'b00100011

`define ALU_CLZ_OP  8'b10110000
`define ALU_CLO_OP  8'b10110001

`define ALU_MULT_OP  8'b00011000
`define ALU_MULTU_OP  8'b00011001
`define ALU_MUL_OP  8'b10101001


`define ALU_MADD_OP  8'b10100110
`define ALU_MADDU_OP  8'b10101000
`define ALU_MSUB_OP  8'b10101010
`define ALU_MSUBU_OP  8'b10101011

`define ALU_DIV_OP  8'b00011010
`define ALU_DIVU_OP  8'b00011011

`define ALU_LINK_OP 8'b01010010 //所有需要保存返回地址指令的ALU_OP

`define ALU_LB_OP  8'b11100000
`define ALU_LBU_OP  8'b11100100
`define ALU_LH_OP  8'b11100001
`define ALU_LHU_OP  8'b11100101
`define ALU_LL_OP  8'b11110000
`define ALU_LW_OP  8'b11100011
`define ALU_LWL_OP  8'b11100010
`define ALU_LWR_OP  8'b11100110

`define ALU_SB_OP  8'b11101000
`define ALU_SC_OP  8'b11111000
`define ALU_SH_OP  8'b11101001
`define ALU_SW_OP  8'b11101011
`define ALU_SWL_OP  8'b11101010
`define ALU_SWR_OP  8'b11101110

`define ALU_MFC0_OP 8'b01011101
`define ALU_MTC0_OP 8'b01100000

`define ALU_NOP_OP    8'b00000000



// 指令存储器inst_rom
`define InstMemCapacity 131072   //指存容量（字）
`define InstMemAddrWidth 19  //使用pc地址的18~2位作为存储单元地址
//***************************
//数据存储器
`define RamEnable 1'b1
`define RamDisable 1'b0
`define DataMemCapacity 131072 //数据存储器容量（128k word）单位为字
`define DataMemAddrWidth 19  //使用地址的18~2位作为存储单元地址
//*****************************
//除法信号
`define DivResultReady 1'b1
`define DivResultNoReady 1'b0
`define DivStart 1'b1
`define DivStop 1'b0
`define DivCancel 1'b1
`define DivNoCancel 1'b0
`define DivFinish 1'b1
`define DivNoFinish 1'b0
//**************************


//流水线暂停信号
`define PAUSE 1'b1
`define NO_PAUSE 1'b0
//***********************
//跳转分支指令相关信号
`define JumpEnable 1'b1
`define JumpDisable 1'b0
`define InDelaySlot 1'b1
`define NotInDelaySlot 1'b0
//***************************
//异常信号
`define ExceptionEnable 1'b1
`define ExceptionDisable 1'b0

//**************************
//CP0寄存器地址
`define CP0_REG_COUNT    5'b01001        //可读写
`define CP0_REG_COMPARE    5'b01011      //可读写
`define CP0_REG_STATUS    5'b01100       //可读写
`define CP0_REG_CAUSE    5'b01101        //只读 可写部分位
`define CP0_REG_EPC    5'b01110          //可读写
`define CP0_REG_PRId    5'b01111         //只读
`define CP0_REG_CONFIG    5'b10000       //只读
//************************************
//中断相关
`define InterruptAssert 1'b1
`define InterruptNotAssert 1'b0

//**************************************